package com.bracketbird.client.gui.club.tournament;


import com.bracketbird.client.gui.club.tournament.rtc.*;
import com.bracketbird.client.model.*;
import com.bracketbird.clientcore.gui.*;
import com.bracketbird.clientcore.util.*;

/**
 *
 */
public class ParticipatersFocusManager extends VerticalFocusManager {


    private Participaters participaters;

    public ParticipatersFocusManager(Participaters participaters) {
        super();
        this.participaters = participaters;
    }


    //comming from it self
    public void down(FocusKeyDownEvent e) {
        int index = getIndex(e.getSource());
        if (isLastItem(index) && lastTeamHasPlayers()) {
            RTC.getInstance().addTeam(new PlayingTeam(), true);
        }
        else {
            super.down(e);
        }
    }

    private boolean lastTeamHasPlayers() {
        return !participaters.lastTeamHasPlayers();
    }


    //coming from horizontal manager
    public void down(FocusKeyDownEvent e, int index, FocusManager child) {
        int fmIndex = getIndex(child);

        if (isLastItem(fmIndex) && lastTeamHasPlayers()) {
            RTC.getInstance().addTeam(new PlayingTeam(), true);
        }
        else {
            super.down(e, index, child);
        }
    }


}